layui.use(['layer', 'form'], function() {
	var $ = layui.$
	,layer = layui.layer
	,form = layui.form;
	// 验证
	form.verify({
        userName: function(value) {
            if (value.length <= 0) {
                return '请输入账号!';
            }
        },
        password: function(value) {
        	if (value.length <= 0) {
        		return '请输入密码!';
        	}
        }
    });
	// form提交
	form.on('submit(formLogin)', function(data){
		$.post("/doLogin", data.field, function(result){
			if (result.type=="SUCCESS") {
				window.location.href="/index";
			} else {
				layer.msg(result.msg, {icon: 5});
			}
		});
		return false; // Ajax提交必须加这行,否则默认form提交
	});
});